var config = {
  publicUrl: "http://localhost:3000/users/"
};
//清除cookie
$(".clear_cookie").click(function () {
  var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
  if (keys) {
    for (var i = keys.length; i--;) {
      document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString();//清除当前域名下的,例如：m.kevis.com
      document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString();//清除当前域名下的，例如 .m.kevis.com
      document.cookie = keys[i] + '=0;path=/;domain=kevis.com;expires=' + new Date(0).toUTCString();//清除一级域名下的或指定的，例如 .kevis.com
    }
  }
  window.location.href = "login.html"
});


$.ajax({
  url: `${config.publicUrl}list_special/${encodeURIComponent(getCookie(window.localStorage.getItem("keys")))}`,
  method: "get",
}).then(res => {
  // console.log(res);
  $("#user_name").text(res)
})

//获取cookie
function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=")
    if (c_start != -1) {
      c_start = c_start + c_name.length + 1
      c_end = document.cookie.indexOf(";", c_start)
      if (c_end == -1) c_end = document.cookie.length
      return unescape(document.cookie.substring(c_start, c_end))
    }
  }
  return ""
}




//右边侧边菜单
var data = [{
  text: '用户模块',
  iconCls: 'fa fa-wpforms',
  state: 'open',
  children: [{
    text: '用户管理',
    dataurl:'/user/'
  }]
}, {
  text: '分类模块',
  iconCls: 'fa fa-at',
  selected: true,
  children: [{
    text: '分类管理',
    dataurl:'/cate/'
  }]
}, {
  text: '新闻模块',
  iconCls: 'fa fa-table',
  children: [{
    text: '新闻管理',
    dataurl:'/news/'
  }]
}, {
  text: '产品模块',
  iconCls: 'fa fa-table',
  children: [{
    text: '产品管理',
    dataurl:'/product/'
  }]
}, {
  text: '评论模块',
  iconCls: 'fa fa-table',
  children: [{
    text: '评论管理',
    dataurl:'/comment/'
  }]
}];



  $("#slide_menu").sidemenu({
      data:data,
      onSelect:function(item){
        // console.log(item);
        $('#tab').tabs('add',{
          title: item.text,
          content: '<iframe style="width:100%;height:150%" src="'+item.dataurl+'"></iframe>',
          closable: true
        });
      }
    })